<template>
  <div class="full">
    <full-page
      ref="fullpage"
      :options="options"
      id="fullpage"
      v-if="config.subsystems"
    >
      <div class="section pg-bg1">
        <div class="full mask">
          <SystemIntro v-show="curIndex == 0" />
        </div>
      </div>
      <div class="section pg-bg2">
        <div class="full mask">
          <Font v-show="curIndex == 1" />
        </div>
      </div>

      <div class="section pg-bg3">
        <div class="full mask">
          <Back v-show="curIndex == 2" />
        </div>
      </div>

      <div class="section pg-bg4">
        <div class="full">
          <Deploy v-show="curIndex == 3" />
        </div>
      </div>

      <div class="section" v-for="(item, i) in subsystems" :key="i">
        <div class="full">
          <SubSystem
            :data="item"
            v-show="curIndex == i + 4"
            @enter-system="handleEnter"
          />
        </div>
      </div>
    </full-page>
    <div class="foot-operates" v-show="config.subsystems">
      <Button
        size="large"
        class="enter-btn"
        @click="handleClick"
        :loading="loading"
        >登录个人账号<Icon type="ios-arrow-forward"
      /></Button>
      <Button
        size="large"
        type="primary"
        class="enter-btn"
        @click="login"
        :loading="loading"
        >使用默认账号<Icon type="ios-arrow-forward"
      /></Button>
    </div>
    <Spin v-if="!config.subsystems" fix>
      <Icon type="ios-loading" size="18" class="demo-spin-icon-load"></Icon>
      <div>加载中</div>
    </Spin>
  </div>
</template>

<script>
import { mapActions } from "vuex";
import SystemIntro from "./SystemIntro.vue";
import Font from "./Font.vue";
import SubSystem from "./SubSystem.vue";
import Back from "./Back.vue";
import Deploy from "./Deploy.vue";

export default {
  name: "Introduce",
  components: { SystemIntro, Font, SubSystem, Back, Deploy },
  data() {
    return {
      loading: false,
      curIndex: 0,
    };
  },
  computed: {
    config() {
      return this.$store.getters.curConfig;
    },
    options() {
      let res = {};
      if (this.config && this.config.options) {
        res = {
          ...this.config.options,
          onLeave: this[this.config.options.onLeave],
        };
      }
      return res;
    },
    subsystems() {
      return this.config && this.config.subsystems
        ? this.config.subsystems
        : [];
    },
  },

  mounted() {
    console.log(this.subsystems);
  },
  methods: {
    ...mapActions(["userLogin", "getResource"]),
    async handleEnter(name) {
      this.loading = true;
      await this.userLogin({
        name: "user",
        password: "pass123",
      });
      await this.getResource();
      this.$router.push({
        name,
      });
      this.loading = false;
    },
    async login() {
      try {
        this.loading = true;
        await this.userLogin({
          name: "user",
          password: "pass123",
        });
        await this.getResource();
        this.$router.push({
          name: "Portal",
        });
        this.loading = false;
      } catch (err) {
        console.log(err.message);
        this.loading = false;
      }
    },
    handleClick() {
      this.$router.push({
        name: "Login",
      });
    },
    hasScrollBar(origin, destination) {
      console.log(origin);
      setTimeout(() => {
        this.curIndex = destination.index;
      }, 500);
    },
  },
};
</script>

<style lang="scss" scoped>
.mask {
  background: #2525255e;
}
.pg-bg1 {
  background: url(~@/assets/images/bg1.jpg) no-repeat;
  background-size: 100% 100%;
}
.pg-bg2 {
  background: url(~@/assets/images/bg2.jpg) no-repeat;
  background-size: 100% 100%;
}
.pg-bg3 {
  background: url(~@/assets/images/moleculer.png) no-repeat;
  background-size: 100% 100%;
}
.pg-bg4 {
  background: white;
}

.foot-operates {
  position: fixed;
  bottom: 30px;
  height: 3rem;
  line-height: 3rem;
  width: 100%;
  text-align: center;
  .enter-btn {
    width: 15rem;
    height: 3rem;
    font-size: 1.3rem;
    border-radius: 1.5rem;
    margin-right: 3rem;
    i {
      margin-left: 0.5rem;
    }
  }
}
.demo-spin-icon-load {
  animation: ani-demo-spin 1s linear infinite;
}
@keyframes ani-demo-spin {
  from {
    transform: rotate(0deg);
  }
  50% {
    transform: rotate(180deg);
  }
  to {
    transform: rotate(360deg);
  }
}
.demo-spin-col {
  height: 100px;
  position: relative;
  border: 1px solid #eee;
}
</style>
